// import { ProtocolComponent, UseComponent } from "@components/Apps/Lidar/LidarComponent";
import ExamComponent from "@components/Apps/Exam/ExamComponent";
import AppSettings from "@runtime/base/AppSettings";
import { ClientMessage } from "@runtime/generate/message/ClientMessage";
import DeviceComponent from "@runtime/module/Device/DeviceComponent";
import MessageHandler from "@runtime/module/Handler/MessageHandler";
import { ElMessage } from 'element-plus'
import 'element-plus/dist/index.css'

/**
 * 设备更新消息处理器
 */
export default class LaserRadarSettingsUpdateMessageHandler extends MessageHandler<ClientMessage.LaserRadarSettingsMessage> {            
    protected async RunAsync(message: ClientMessage.LaserRadarSettingsMessage): Promise<void> {
        console.log('雷达设置消息更新',message);
        if(message == undefined) {
            return 
        } else {
            ExamComponent.Default.LaserRadarSettingData.value = message

            if(!ExamComponent.Default.RegulationGame.value && ExamComponent.Default.isSubmit.value) {
                console.log('非比赛模式下');
                
                if(message.StartAngle == Number(ExamComponent.Default.fieldAngle.value[0]) && message.EndAngle == Number(ExamComponent.Default.fieldAngle.value[1])) {
                    console.log('值一样，正确');
                    
                    ExamComponent.Default.ViewingAngle.value = true
                    ExamComponent.Default.LaserRadarScore.value = 100
                    ElMessage({
                        message: '配置正确',
                        type: 'success',
                    })
                } else {
                    console.log('值不同，错误');
                    ExamComponent.Default.ViewingAngle.value = false
                    ExamComponent.Default.LaserRadarScore.value = 0
                    ElMessage({
                        message: '配置错误',
                        type: 'error',
                    })
                }
                console.log('激光雷达任务配置分数',ExamComponent.Default.LaserRadarScore.value);
            } else if(ExamComponent.Default.RegulationGame.value && ExamComponent.Default.isSubmit.value){
                let score = 0
                if(message.MSOPPort == ExamComponent.Default.setValue.value.MSOPPortValue) {
                    ExamComponent.Default.isMSOPPort.value = true
                    score +=25
                } else {
                    ExamComponent.Default.isMSOPPort.value = false
                }
                if(message.DIFOPPort == ExamComponent.Default.setValue.value.DIFOPPortValue) {
                    ExamComponent.Default.isDIFOPPort.value = true
                    score +=25
                } else {
                    ExamComponent.Default.isDIFOPPort.value = false
                }
                if(message.StartAngle ==  ExamComponent.Default.setValue.value.start && message.EndAngle == ExamComponent.Default.setValue.value.end) {
                    ExamComponent.Default.ViewingAngle.value = true
                    score +=25
                } else {
                    ExamComponent.Default.ViewingAngle.value = false
                }
                if(message.RotateSpeed == ExamComponent.Default.setValue.value.value) {
                    ExamComponent.Default.isRotateSpeed.value = true
                    score +=25
                } else {
                    ExamComponent.Default.isRotateSpeed.value = false
                }
                ExamComponent.Default.LaserRadarScore.value = score
                
                ElMessage({
                    message: '配置完成',
                    type: 'success',
                })
                console.log('激光雷达任务配置分数',ExamComponent.Default.LaserRadarScore.value);
            }
        }
    }
}
